<?php

// vars
$keyword = $this->request->getParam('keyword');
$source = $this->request->getParam('source');

// sources
$ssource = "<option value=''> ".$this->translate->_('Select Source')."</option>";
foreach($this->sources as $id => $val) {
	$sel = $source && $source == $id ? 'selected="selected"' : null;
	$ssource .= "<option value='{$id}' {$sel}>{$val['title']}</option>";
}

echo "<h3>".$this->translate->_("Search News")."</h3>
			<form id='news_search_form'>
				<table width='100%' cellspacing='3' cellpadding='3' border='0'>
					<tr>
						<td><label>".$this->translate->_("Keywords")."</label></td>
						<td style='padding-left: 5px;'><input type='text' name='keyword' value='{$keyword}' /></td>
					</tr>
						<td><label>".$this->translate->_("Source")."</label></td>
						<td style='padding-left: 5px;'><select name='source'>{$ssource}</select></td>
					</tr>
					<tr>
						<td colspan='2'><input class='srcbtn' type='submit' value='".$this->translate->_("Go")."' /><input class='srcbtn' type='button' id='search_reset' value='".$this->translate->_("Reset")."' /></td>
					</tr>
				</table>
			</form>";

?>
<script type="text/javascript">
(function($){
	$.fn.serializeURL = function() {
		var url = '';

		jQuery.map($(this).serializeArray(), function(n, i){
			if(n['value'])
				url += n['name'] + '/' + n['value'] + '/';
		});

		return url;
	};
})(jQuery);

READY(function(){
	$('#news_search_form').submit(function(e){
		e.preventDefault();
		Petolio.go(SITE_URL + 'news/index/' + $(this).serializeURL());
	});

	$("#search_reset").click(function(e) {
		e.preventDefault();
		$("#news_search_form").find('input, select').each(function(index) {
			if($(this).attr('class') != 'srcbtn')
				$(this).val('');
		});
		$("#news_search_form").submit();
	});
});
</script>